﻿@model IList<XCode.Membership.Menu>
@using NewLife;
@using NewLife.Web;
@using XCode;
@using XCode.Configuration;
@using System.Web.Mvc;
@using System.Web.Mvc.Ajax;
@using System.Web.Mvc.Html;
@using System.Web.Routing;
@{
    var fact = ViewBag.Factory as IEntityOperate;
    var page = ViewBag.Page as Pager;
    var fields = ViewBag.Fields as IList<FieldItem>;
    var enableSelect = this.EnableSelect();
    //var provider = ManageProvider.Provider;
}
<div class="kt-widget4" style="overflow-x:auto;">
    <table class="table table-striped table-bordered table-hover table-checkable kt-datatable__table table-sm ">
        <thead>
            <tr class="kt-datatable__row">
                @if (enableSelect)
                {
                    <th class="kt-datatable__cell--center kt-datatable__cell kt-datatable__cell--check" style="width:20px;">
                        <label class="kt-checkbox kt-checkbox--single kt-checkbox--all kt-checkbox--solid">
                            <input type="checkbox" id="chkAll" title="全选" />
                            <span></span>
                        </label>
                    </th>
                }
                @*<th class="text-center hidden-md hidden-sm hidden-xs"><a href="@Html.Raw(page.GetSortUrl("ID"))">编号</a></th>*@
                <th class="text-left"><a href="@Html.Raw(page.GetSortUrl("TreeNodeName"))">节点名</a></th>
                <th class="text-left"><a href="@Html.Raw(page.GetSortUrl("DisplayName"))">显示名</a></th>
                <th class="text-left"><a href="@Html.Raw(page.GetSortUrl("Url"))">链接</a></th>
                <th class="text-right"><a href="@Html.Raw(page.GetSortUrl("Sort"))">排序</a></th>
                <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Visible"))">可见</a></th>
                <th class="text-center" title="必要。必要的菜单，必须至少有角色拥有这些权限，如果没有则自动授权给系统角色"><a href="@Html.Raw(page.GetSortUrl("Necessary"))">必要</a></th>
                <th class="text-left" title="权限子项。逗号分隔，每个权限子项名值竖线分隔"><a href="@Html.Raw(page.GetSortUrl("Permission"))">权限子项</a></th>
                @if (this.Has(PermissionFlags.Update, PermissionFlags.Delete))
                {
                    <th class="text-center">升</th>
                    <th class="text-center">降</th>
                    <th class="text-center">操作</th>
                }
            </tr>
        </thead>
        <tbody>
            @foreach (var entity in Model)
            {
                var permission = entity.Permission + "";
                var p = entity.Parent as IEntityTree;
                if (p == null)
                {
                    p = fact.EntityType.GetValue("Root") as IEntityTree;
                }
                var id = entity.ID;
                <tr>
                    @if (enableSelect)
                    {
                        <td class="text-center" style="width:20px;">
                            <label class="kt-checkbox kt-checkbox--single kt-checkbox--all kt-checkbox--solid">
                                <input type="checkbox" name="keys" value="@entity.ID" />
                                <span></span>
                            </label>
                        </td>
                    }
                    @*<td class="text-center hidden-md hidden-sm hidden-xs">@entity.ID</td>*@
                    <td class="text-left">@entity.TreeNodeName</td>
                    <td class="text-left">@entity.DisplayName</td>
                    <td class="text-left">@entity.Url</td>
                    <td class="text-right">@entity.Sort.ToString("n0")</td>
                    <td class="text-center">
                        <span>
                            <i class="la la-@(entity.Visible ? "check" : "close")" style="color: @(entity.Visible ? "green" : "red");"></i>
                        </span>
                    </td>
                    <td class="text-center">
                        <span>
                            <i class="la la-@(entity.Necessary ? "check" : "close")" style="color: @(entity.Necessary ? "green" : "red");"></i>
                        </span>
                    </td>
                    <td title="@permission">@(permission.Length > 35 ? permission.Substring(0, 25) + "......" : permission)</td>
                    @if (this.Has(PermissionFlags.Update, PermissionFlags.Delete))
                    {
                        <td class="text-center" style="width:50px;">
                            @if (p != null && p.Childs != null && p.Childs.Count > 0 && entity != p.Childs[0])
                            {
                                <a href="@Url.Action("Up", new { id })"><span class="la la-angle-up" style="color: green;"></span></a>
                            }
                        </td>
                        <td class="text-center" style="width:50px;">
                            @if (p != null && entity != p.Childs[p.Childs.Count - 1])
                            {
                                <a href="@Url.Action("Down", new { id })"><span class="la la-angle-down" style="color: red;"></span></a>
                            }
                        </td>
                        <td class="text-right" style="width: 90px;">
                            @Html.Partial("_List_Data_Action", (Object)entity)
                        </td>
                    }
                </tr>
            }
        </tbody>
    </table>
</div>